package com.ys.otms.controller;

import com.ys.otms.services.IThirdServices;
import com.ys.otms.utils.JsonUtil;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/third")
public class ThirdController {
    private static Logger logger = LoggerFactory.getLogger(ThirdController.class);

    @Autowired
    private IThirdServices iThirdServices;

    @RequestMapping("/queryShip")
    @ResponseBody
    public JSONObject queryShip(HttpServletRequest request) {
        JSONObject objRet = new JSONObject();
        try {
            JSONObject obj = JsonUtil.getJSONObject(request);
            objRet = iThirdServices.queryShip(obj);
        } catch (Exception e) {
            objRet.put("msg","error");
            logger.error("ThirdController queryShip error", e);
        }
        return objRet;
    }

    @RequestMapping("/getSingleShip")
    @ResponseBody
    public JSONObject getSingleShip(HttpServletRequest request) {
        JSONObject objRet = new JSONObject();
        try {
            JSONObject obj = JsonUtil.getJSONObject(request);
            objRet = iThirdServices.getSingleShip(obj);
        } catch (Exception e) {
            objRet.put("msg","error");
            logger.error("ThirdController getSingleShip error", e);
        }
        return objRet;
    }

    @RequestMapping("/getManyShip")
    @ResponseBody
    public JSONObject getManyShip(HttpServletRequest request) {
        JSONObject objRet = new JSONObject();
        try {
            JSONObject obj = JsonUtil.getJSONObject(request);
            objRet = iThirdServices.getManyShip(obj);

        } catch (Exception e) {
            objRet.put("msg","error");
            logger.error("ThirdController getManyShip error", e);
        }
        return objRet;
    }

    @RequestMapping("/getAreaShip")
    @ResponseBody
    public JSONObject getAreaShip(HttpServletRequest request) {
        JSONObject objRet = new JSONObject();
        try {
            JSONObject obj = JsonUtil.getJSONObject(request);
            objRet = iThirdServices.getAreaShip(obj);

        } catch (Exception e) {
            objRet.put("msg","error");
            logger.error("ThirdController getAreaShip error", e);
        }
        return objRet;
    }

    @RequestMapping("/getPortOfCallByShip")
    @ResponseBody
    public JSONObject getPortOfCallByShip(HttpServletRequest request) {
        JSONObject objRet = new JSONObject();
        try {
            JSONObject obj = JsonUtil.getJSONObject(request);
            objRet = iThirdServices.getPortOfCallByShip(obj);
        } catch (Exception e) {
            objRet.put("msg","error");
            logger.error("ThirdController getShipInfo error", e);
        }
        return objRet;
    }

    @RequestMapping("/getShipTrack")
    @ResponseBody
    public JSONObject getShipTrack(HttpServletRequest request) {
        JSONObject objRet = new JSONObject();
        try {
            JSONObject obj = JsonUtil.getJSONObject(request);
            objRet = iThirdServices.getShipTrack(obj);
        } catch (Exception e) {
            objRet.put("msg","error");
            logger.error("ThirdController getShipTrack error", e);
        }
        return objRet;
    }

    @RequestMapping("/updateShips")
    @ResponseBody
    public JSONObject updateShips(HttpServletRequest request) {
        JSONObject objRet = new JSONObject();
        try {
            JSONObject obj = JsonUtil.getJSONObject(request);
            objRet = iThirdServices.updateShips(obj);
        } catch (Exception e) {
            objRet.put("msg","error");
            logger.error("ThirdController getShipTrack error", e);
        }
        return objRet;
    }

}
